package com.midea.ai.air.ui.home.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.common.ConsVal;
import com.midea.ai.air.ui.home.ActivityDetails;
import com.midea.ai.air.ui.more.adapter.MainListAdapter;
import com.midea.ai.air.ui.more.data.MainListItem;
import com.midea.ai.air.utils.JumpUtils;
import com.midea.ai.air.view.BottomDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ouyangdi on 2016/4/5.
 * 编辑房间Fragment
 */
public class EditRoomFragment extends BaseFragment implements View.OnClickListener{
    private ArrayList<MainListItem> mData = new ArrayList<>();
    private MainListAdapter mAdapter;
    private ListView mListView;
    private TextView mTvNew;

    //底部弹窗相关
    private List<BottomDialog.ListItem> mRooms = new ArrayList<>();
    BottomDialog mBotDialog;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_edit_room, container, false);
        initData();
        initViews(view);
        return view;
    }

    private void initData() {
        mData.add(new MainListItem(R.drawable.air_home_edit_room_myhome, getString(R.string.air_home_edit_room_my_home),false, true));
        mData.add(new MainListItem(R.drawable.air_home_edit_room_living, getString(R.string.air_home_edit_room_main),false, true));
        mData.add(new MainListItem(R.drawable.air_home_edit_room_bedroom, getString(R.string.air_home_edit_room_bedroom), false, false));
        mAdapter = new MainListAdapter(getActivity(), mData);

        mRooms.add(new BottomDialog.ListItem(getString(R.string.air_home_edit_room_living)));
        mRooms.add(new BottomDialog.ListItem(getString(R.string.air_home_edit_room_main)));
        mRooms.add(new BottomDialog.ListItem(getString(R.string.air_home_edit_room_bedroom)));
        mRooms.add(new BottomDialog.ListItem(getString(R.string.air_home_edit_room_study)));
        mRooms.add(new BottomDialog.ListItem(getString(R.string.air_home_edit_room_other)));
    }

    private void initViews(View view) {
        mListView = (ListView)view.findViewById(R.id.list_rooms);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MainListItem item = (MainListItem) parent.getAdapter().getItem(position);
                JumpUtils.toPage(getActivity(), getResources().getString(R.string.air_home_edit_room), getResources().getString(R.string.air_main_home),
                        item.getStrName(), ConsVal.ACTIVITY_TAG_EDIT_ROOM_SET, ActivityDetails.class);
            }
        });

        mTvNew = (TextView)view.findViewById(R.id.btn_new_room);
        mTvNew.setOnClickListener(this);

        mBotDialog = new BottomDialog(getActivity()).builder().setTitle(getString(R.string.air_home_edit_room_add)).addListItems(mRooms);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_new_room:
                mBotDialog.show();
                break;
        }
    }
}
